package com.wlp.pengpicturebackend.exception;

/**
 * 异常处理工具类
 *
 * @author wlp
 * @date 2025/01/01 10:34
 **/
public class ThrowUtils {

    /**
     * 条件成立则抛出异常
     *
     * @param condition:        条件
     * @param runtimeException: 异常
     * @Author: wlp
     * @Date: 2025/1/1 10:36
     * @return: void
     **/
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛出异常
     *
     * @param condition: 条件
     * @param errorCode: 异常
     * @Author: wlp
     * @Date: 2025/1/1 10:36
     * @return: void
     **/
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 条件成立则抛出异常
     *
     * @param condition: 条件
     * @param errorCode: 异常
     * @param message:  异常信息
     * @Author: wlp
     * @Date: 2025/1/1 10:36
     * @return: void
     **/
    public static void throwIf(boolean condition, ErrorCode errorCode,String message) {
        throwIf(condition, new BusinessException(errorCode,message));
    }
}
